package ncov.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @author WuChangJian
 * @date 2020/6/5 20:27
 * 自定义转化器：实现
 * @see ncov.model.ReportRecord#currentHealth
 * 数字到字符串的转变
 */
public class HealthConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return "感染".equals(cellData.getStringValue()) ? -1 : ("正常".equals(cellData.getStringValue()) ? 0 : 1);
    }

    @Override
    public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new CellData(integer == 0 ? "正常" : (integer == -1 ? "感染" : "疑似"));
    }
}
